import os
# 打开文件
fo = open("runoob.txt", "w")
fo.write('nihao\n')
print ("文件名为: ", fo.name)

# 刷新缓冲区
fo.flush()

# 关闭文件
fo.close()

with os.popen(r'ping baidu.com', 'r') as f:
    text=f.read()
    print(text)
   